package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import entity.InfoManage;

public class InfoManageDao extends SqlBase<InfoManage> {
	
	public List<Date> getDate(){
		String sql="select DISTINCT DATE from infomanage order by date desc";
		List<Date> dates=new ArrayList<>();
		try {
			Statement stm=conn.createStatement();
			ResultSet rs=stm.executeQuery(sql);
			while(rs.next()){
				dates.add(rs.getDate("date"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dates;		
	}
	
	public List<InfoManage> getByDate(String date){
		String sql="select * from infomanage where date=\""+date+"\"";
		List<InfoManage> ims=new ArrayList<>();
		System.out.println("infomanagedao:"+sql);
		try {
			Statement stm=conn.createStatement();			
			ResultSet rs=stm.executeQuery(sql);
			while(rs.next()){
				InfoManage im=new InfoManage();
				im.setId(rs.getInt("id"));
				im.setTeacher_Id(rs.getInt("teacher_id"));
				im.setCourses_Id(rs.getInt("courses_id"));
				im.setScore_Num(rs.getInt("score_num"));
				ims.add(im);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return ims;
	}
}
